{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox-content layui-form">
        <div class="layui-row layui-col-space10 layui-form-item ">
            <input type="hidden" name="ag_id" value="{$data.ag_id}">
            <div class="layui-form-item layui-col-xs-offset1 layui-col-xs8">
                <label class="layui-form-label">名称：</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="ag_name" lay-verify="required" placeholder="商品名称" value="{$data.ag_name}">
                </div>
            </div>
            <div class="layui-form-item layui-col-xs-offset1 layui-col-xs8">
                <label class="layui-form-label">分类：</label>
                <div class="layui-input-block">
                    <select name="ag_type" lay-verify="required" lay-search="">
                        <option value="">请选择分类</option>
                        {if !empty($cate)}
                        {foreach name="cate" item="vo"}
                        <option value="{$vo.id}" {eq name="$data.ag_type" value="$vo.id"}selected{/eq}>{$vo.name}</option>
                        {/foreach}
                        {/if}
                    </select>
                </div>
            </div>
            <div class="layui-form-item layui-col-xs-offset1 layui-col-xs8">
                <label class="layui-form-label">缩略图：</label>
                <input type="hidden" name="ag_thumb" id="lay-img" lay-verify="img" value="{$data.ag_thumb}">
                <div class="layui-input-block">
                    <div id="lay-upload">上传图片</div>
                    <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                        预览图：
                        <div class="layui-upload-list" id="lay-list">
                            <img src="{$data.ag_thumb}" style="height: 92px;margin: 0 10px 10px 0;cursor:pointer;" onerror="this.src='/static/admin/images/no_img.jpg'">
                        </div>
                    </blockquote>
                </div>
            </div>
            <div class="layui-form-item layui-col-xs-offset1 layui-col-xs8">
                <label class="layui-form-label">价格：</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="ag_money" lay-verify="required" placeholder="商品价格" value="{$data.ag_money}">
                </div>
            </div>
            <div class="layui-form-item layui-col-xs-offset1 layui-col-xs8">
                <label class="layui-form-label">积分：</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="ag_jifen" lay-verify="required" placeholder="商品积分" value="{$data.ag_jifen}">
                </div>
            </div>
            <div class="layui-form-item layui-col-xs-offset1 layui-col-xs8">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="component-form-element">保存
                    </button>
                    <button class="layui-btn layui-btn-primary" onclick="wk.layer_close('close')">关闭</button>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script type="text/javascript" src="__JS__/webupload/webuploader_upload.js"></script>
<script>
    wk.uploadImg("{:url('Upload/upload')}",2,'','');
    layui.use(['form'], function() {
        var form = layui.form;
        form.verify({
            img:function(value,item){
                if(!value){
                    return '上传缩略图';
                }
            }
        });
        form.on('submit(component-form-element)', function (data) {
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('productEdit')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        layer.msg(res.msg,{icon:1,time:1500,shade:0.1},function(index){
                            wk.layer_close();
                        })
                    } else {
                        $(".layui-btn").removeClass('layui-disabled').removeAttr('disabled');
                        wk.error(res.msg);
                        return false;
                    }
                }
            })
        });
    });
</script>
</body>
</html>